class AttachmentLink < ActiveRecord::Base
  belongs_to :attachable, :polymorphic => true, :counter_cache => :attachments_count
  belongs_to :attachment

  def self.find_attachments_for( array )
    id_list = array.collect( &:id )
    klass = array[0].class
    find( :all,
          :conditions => ['attachable_id in (?) and attachable_type = ?',
                           id_list, klass.to_s ]
        ).collect( &:attachment )
  end
end
